/* 
 * File:   FileCachedCleanServer.h
 * Author: dell
 *
 * Created on 2012年11月21日, 下午4:26
 */



#ifndef FILECACHEDCLEANSERVER_H
#define	FILECACHEDCLEANSERVER_H

#include "common.h"
#include <evhttp/libev.h>
#include <evhttp/Process.h>
#include "config/RapidConfigManager.h"
#include <string>
#include "ProcessMessage.h"
#include <evhttp/Timer.h>

namespace Rapid{
    class FileCachedCleanServer : protected Process, protected Timer{
    public:
        FileCachedCleanServer(RapidConfigManager* rapidConfigManager, std::string& hdir);
        virtual ~FileCachedCleanServer();
        
        /**
         * 启动服务
         * @param daemon 指示是否以守护进程方式启动
         */
        virtual bool start(void* param=NULL); 
        
    protected:
       /**
        * @see Process#run(void* param=NULL)
        */
        virtual int run(void* param=NULL);
        
       virtual bool onTimerEvent(const TimerEvent* e);          
        
    private:
        void notifyCallback(ev::io& io, int revents);
        
    private:
        RapidConfigManager* rapidConfigManager;
        std::string homeDir; //服务主目录, 尾部有"/"
        ProcessMessage processMessage;
        
        typedef struct INotifyInfo{
            int fd;
            int wd;
            uint32_t mask;
            ev::io notifyev;
        }INotifyInfo;
        
    };
}
#endif	/* FILECACHEDCLEANSERVER_H */

